package com.wanchuang.shengfubao.module.allow;

/**
 * 文件名 : EarningDetailActivity
 * 创建者 : MangoWang
 * 创建日期 : 2019/11/28 20:06
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.wanchuang.shengfubao.R;
import com.wanchuang.shengfubao.base.BaseActivity;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class AllowRecordActivity extends BaseActivity {

    Unbinder unbinder;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;


    private List<Fragment> fragmentList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_allwo_record);
        unbinder = ButterKnife.bind(this);
        tvTitle.setText("划拨审核记录");
        initView();
        initListener();
    }

    private void initListener() {
        backIv.setOnClickListener(view -> finish());
        tvTitleRight.setOnClickListener(v -> {

        });

    }

    protected void initView() {
        String[] titles = {"入库审核", "出库审核","已撤回"};
        fragmentList = new ArrayList<>();
        fragmentList.add(AllowRecordFragment.NewInstance(2));
        fragmentList.add(AllowRecordFragment.NewInstance(3));
        fragmentList.add(AllowRecordFragment.NewInstance(4));
        viewPager.setOffscreenPageLimit(3);
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }

        });
        //设置图标
        tabLayout.setupWithViewPager(viewPager);

        for (int i = 0; i < titles.length; i++) {
            tabLayout.getTabAt(i).setCustomView(getTabView(titles[i]));
        }
    }

    public View getTabView(String tabName) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.tab_select_layout, null);
        TextView tv_tab = view.findViewById(R.id.tv_tab);
        tv_tab.setText(tabName);
        return view;
    }

}
